package dicebot.tools.dice;

import java.util.List;

public class LongAdd extends DiceExpression {

    public List<DiceExpression> vars;

    @Override
    public DiceExpression simplify() throws Exception {
        boolean simp = true;
        for (DiceExpression var : vars) {
            if (!(var instanceof Number)) {
                simp = false;
                break;
            }
        }
        if (simp) {
            int sum = 0;
            for (DiceExpression var : vars) {
                sum += ((Number) var).value;
            }
            return new Number(sum);
        } else {
            for (int i = 0; i < vars.size(); i++) {
                vars.set(i, vars.get(i).simplify());
            }
            return this;
        }
    }

    public LongAdd (List<DiceExpression> vars) {
        this.vars = vars;
    }

    @Override
    public String toString() {
        String s = vars.get(0).toString();
        for (int i = 1; i < vars.size(); i++) {
            s += vars.get(i).toStringWithSign();
        }
        return s;
    }

    @Override
    public String toStringWithSign() {
        String s = "";
        for (int i = 0; i < vars.size(); i++) {
            s += vars.get(i).toStringWithSign();
        }
        return s;
    }

}